#include('header.html')
<script type="text/javascript">
    changeTab('评分记录');

    function gotoPage(e, page) {
        var pages = ${pages.totalPages};
        var stageId = $('select[name="stage_id"]').val();
        var shopId  = $('select[name="shop_id"]').val();
        var star    = $('select[name="star"]').val();

        var query = "";
        if (stageId !== '') {
            query += ("&stage_id=" + stageId);
        }
        if (shopId !== '') {
            query += ("&shop_id=" + shopId);
        }
        if (star !== '') {
            query += ("&star=" + star);
        }

        var status = $(e).parent().attr("class");
        if (page > 0 && page <= pages && page !== ${pages.number + 1} &&
            status !== "active") {
            location.href = '/admin/record?pageNo=' + page + query;
        }
    }

    function delete_(id) {
        var flag = confirm("确定要删除该项？");
        if (flag) {
            $.post("/markRecord/delete/" + id, function (data) {
                console.log(data);
                if (data.success) {
                    alert("删除成功！");
                    location.reload();
                }
            });
        }
    }
</script>

<div class="record-xcontent">
    <div>
        <div class="col-lg-12 col-xs-12">
            <a class="text-black" href="/admin/record">
                <h4><span class="fa fa-hand-o-right"></span> 评分记录</h4>
            </a>
            <div style="padding: 15px 5px 0;" class="pull-right">
                <div id="loading" class="pull-left hidden" style="padding: 4px 10px;">
                    <img class="" width="20" src="/static/images/loading.jpg" alt="加载中">
                </div>
                <form id="record-search" class="pull-left" method="get">
                    <div class="input-group min-input pull-left" style="width: 100px;">
                        <input name="name" class="form-control min-min-select" value="${name ?! ''}" placeholder="用户名"/>
                    </div>
                    <div class="input-group min-min-input pull-left">
                        <select name="shop_id" class="form-control min-min-select">
                            <option value="">-- 全部公司 --</option>
                            #for(Shop shop : shops)
                            <option value="${shop.id}" ${shop_id?(shop_id.asInt()==shop.id?'selected':''):''}>${shop.name}</option>
                            #end
                        </select>
                    </div>
                    <div class="input-group min-min-input pull-left">
                        <select name="stage_id" class="form-control min-min-select">
                            <option value="">-- 全部阶段 --</option>
                            #for(Stage st : stages)
                            <option value="${st.id}" ${stage_id?(stage_id.asInt()==st.id?'selected':''):''}>${st.name}</option>
                            #end
                        </select>
                    </div>
                    <div class="input-group min-min-input pull-left">
                        <select name="star" class="form-control min-min-select">
                            <option value="">-- 星级 --</option>
                            #set(Map ms = {'4':'优秀', '3':'良好', '2':'及格', '1':'差评'})
                            #for(Map.Entry et : ms)
                            <option value="${et.key}" ${star==et.key?'selected':''}>${et.value}</option>
                            #end
                        </select>
                    </div>
                    <button class="btn btn-info btn-sm">搜索</button>
                </form>
            </div>
        </div>
        <div>
            <div class="col-lg-12 col-xs-12">
                <table class="table table-striped">
                    <thead class="bg-color-x">
                    <tr>
                        <td>索引</td>
                        <td>评分对象</td>
                        <td>评分阶段</td>
                        <td>评分用户</td>
                        <td>星级</td>
                        <td style="width: 180px;">评分时间</td>
                        #if(admin.grade > 1)
                        <td>操作</td>
                        #end
                    </tr>
                    </thead>
                    <tbody>
                        #for(MarkRecord rd : pages.content)
                        <tr>
                            <td>${for.index}</td>
                            <td>${rd.shop.name ?! ''}</td>
                            <td>${rd.stage.name ?! ''}</td>
                            <td>${rd.user.realName ?! '匿名'}</td>
                            <td><span class="star-${rd.star ?! '0'}"></span></td>
                            <td>${rd.time ? rd.time.format('yyyy-MM-dd HH:mm') :''}</td>
                            #if(admin.grade > 1)
                            <td>
                                <button class="btn btn-xs btn-danger" onclick="delete_('${rd.id}')">删除</button>
                            </td>
                            #end
                        </tr>
                        #else
                        <tr><td class="text-center" colspan="7">暂无记录</td></tr>
                        #end
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <!-- 分页按钮 -->
    #if(pages.totalPages > 1)
    <div class="col-lg-12 col-xs-12 text-center">
        <ul style="margin: 0;" class="pagination pagination-sm"></ul>
        <span style="padding-top: 15px; font-size: 12px;" class="pull-right">
            共${pages.totalPages}页，${pages.totalElements}条数据
        </span>
    </div>
    #end
</div>
#include('footer.html')
